<template>
  <div class="container">
    <div class="picture-bar">
      <img src="./images/hotel002.jpg" alt="资源缺失" loading="eager">
    </div>
    <div class="wrapper">
      <h1>{{ !isUser?'登录':'切换用户' }}</h1>
      <div class="input-data">
        <input type="text" required v-model="loginInfo.user">
        <div class="underline"></div>
        <label>Name</label>
      </div>
      <div class="input-data">
        <input type="password" required v-model="loginInfo.password">
        <div class="underline"></div>
        <label>Password</label>
      </div>
      <input type="submit" class="btn-commit" value="提交" @click="commitLogin()">
    </div>
  </div>
</template>

<script>
export default {
  name: "LoginPage",
  data(){
      return {
        loginInfo:{
          user:"",
          password:""
        },
        isUser:false,
    }
  },
  created() {
    this.identificationUser();
  },
  methods:{
    // 提交登录
    commitLogin(){
      this.$store.dispatch("loginUser", this.loginInfo);
      setTimeout(()=>{
        this.$router.push('/').then(()=>{
          this.$router.go(0);
        });
      }, 1000)
    },
    // 用户身份识别
    identificationUser(){
      const localToken = window.localStorage.getItem("TOKEN");
      if (localToken){
        this.isUser = true;
      }
    }
  },
}
</script>

<style scoped lang="less">
.container{
  display: flex;
  justify-content: center;
  height: 600px;
  width: 1240px;

  .picture-bar{
    height: 100%;
    width: clac(1240 - 450)px;
    display: block;

    img{
      height: 100%;
    }
  }
  .wrapper{
    width: 450px;
    background: #fff;
    padding: 30px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);

    .input-data{
      height: 40px;
      width: 100%;
      position: relative;
      margin-top: 17px;

      input{
        height: 100%;
        width: 100%;
        border: none;
        font-size: 17px;
        border-bottom: 2px solid silver;

        &:focus ~ label,
        &:valid ~ label{
          transform: translateY(-20px);
          font-size: 15px;
          color: #4158d0;
        }
        &:focus ~ .underline::before,
        &:valid ~ .underline::before{
          transform: scaleX(1);
        }
      }

      .underline{
        position: absolute;
        height: 3px;
        width: 100%;
        bottom: 0;

        &::before{
          position: absolute;
          content: "";
          height: 100%;
          width: 100%;
          background: #4158d0;
          transform: scaleX(0);
          transition: transform 0.3s ease;
        }
      }

      label{
        position: absolute;
        left: 0;
        bottom: 10px;
        color: gray;
        pointer-events: none;
        transition: all 0.3s ease;
      }
    }

    .btn-commit{
      height: 50px;
      width: 100%;
      background: #c850c0;
      border: none;
      color: #fff;
      font-size: 17px;
      margin-top: 20px;
      cursor: pointer;

      &:hover{
        background: #4158d0;
      }
    }
  }
}

@media(max-width: 1000px){
  .container{
    width: 100%;
    overflow: hidden;
    .picture-bar{
      width: 40%;
      overflow: hidden;
    }
    .wrapper{

      width: 30%;
    }
  }
}
@media(max-width: 400px) {
  .container{
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
    .picture-bar{
      width: 100%;
      display: none;
    }
    .wrapper{
      width: 400px;
    }
  }
}
</style>